home *** CD-ROM | disk | FTP | other *** search
- (*===========================================================================*)
- (* Console I/O -- Overlay *)
- (* *)
- (* Copyright 1988, 1989, 1990, 1991, 1992 by H. Roy Engehausen. All *)
- (* rights reserved. *)
- (* *)
- (*===========================================================================*)
-
- {$O+}
-
- {$UNDEF SEMABUG}
- {$UNDEF NODEBUG}
- {$UNDEF WINBUG}
- {$DEFINE PORTBUG}
- {$UNDEF DUMP_FREE}
- {$UNDEF DUMP_SEARCH}
-
- UNIT BBCONSL;
-
- INTERFACE
-
- VAR
-
- operator_line_c : BOOLEAN;
- op_sw : BOOLEAN;
- opr_line_done : BOOLEAN;
- opr_window_open : BOOLEAN;
-
- PROCEDURE operator_line;
- PROCEDURE close_operator_session;
- PROCEDURE operator_init_session;
-
- IMPLEMENTATION
-
- USES
- CRT,
- bbconio,
- bbdummy,
- bbdump,
- bbmem,
- bbmisci,
- bbsdata,
- bbsema2,
- bbsess,
- bbstr,
- bbtask,
- bbuf,
- bbwin;
-
- {$I EXTKEY.PAS}
-
- CONST
- line_buffer_max = 10;
- line_max = 79;
-
- VAR
- current_buffer : BYTE;
- insert_buffer : BYTE;
- high_buffer : BYTE;
- line_buffer : ARRAY[1..line_buffer_max] OF STRING[line_max];
- operator_insert : BOOLEAN;
- operator_line_in : ^STRING;
- this_key : CHAR;
-
- PROCEDURE do_key; FORWARD;
- PROCEDURE function_key; FORWARD;
-
- (*===========================================================================*)
- (* Get a line from the operator -- wait for it! *)
- (*===========================================================================*)
-
- PROCEDURE operator_line;
-
- BEGIN;
-
- (*-----------------------------------------------------------------------*)
- (* Initialize *)
- (*-----------------------------------------------------------------------*)
-
- operator_line_in := @active_tcb^.i_data.str_data;
-
- opr_line_done := FALSE;
- operator_line_c := FALSE;
- operator_line_in^ := '';
-
- (*-----------------------------------------------------------------------*)
- (* Call the non-overlayed routine "operator_io_loop" to wait for a *)
- (* key stroke from the operator. We fall out of the loop if the end *)
- (* of the line is reached *)
- (*-----------------------------------------------------------------------*)
-
- WHILE NOT operator_io_loop DO
- do_key;
-
- (*-----------------------------------------------------------------------*)
- (* Special key! *)
- (*-----------------------------------------------------------------------*)
-
- IF operator_line_c THEN
- BEGIN;
- operator_line_in^ := '';
- active_tcb^.i_data.long_length := 0;
- EXIT;
- END
- ELSE
- active_tcb^.i_data.long_length := LENGTH(operator_line_in^);
-
- (*-----------------------------------------------------------------------*)
- (* Open operator window if not already open *)
- (*-----------------------------------------------------------------------*)
-
- IF NOT opr_window_open THEN
- BEGIN;
-
- window_activate(window_operator);
- opr_window_open := TRUE;
-
- END;
-
- END;
-
- (*===========================================================================*)
- (* Handle operator's key stroke *)
- (*===========================================================================*)
-
- PROCEDURE do_key;
-
- VAR
- i : BYTE;
-
- BEGIN;
-
- (*-----------------------------------------------------------------------*)
- (* Read the key *)
- (*-----------------------------------------------------------------------*)
-
- this_key := READKEY;
-
- (*-----------------------------------------------------------------------*)
- (* Special key! *)
- (*-----------------------------------------------------------------------*)
-
- IF this_key = CHR(0) THEN
- BEGIN;
- this_key := READKEY;
- function_key;
- EXIT;
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Everything else *)
- (*-----------------------------------------------------------------------*)
-
- window_select(window_reset);
-
- CASE this_key OF
-
- (*-----------------------------------------------------------------------*)
- (* CR -- Line done. Clear it off the screen *)
- (*-----------------------------------------------------------------------*)
-
- cr : BEGIN;
-
- IF LENGTH(operator_line_in^) = 0 THEN
- operator_line_in^ := ' '
- ELSE
- BEGIN;
- IF high_buffer < line_buffer_max THEN
- BEGIN;
- INC(high_buffer);
- insert_buffer := high_buffer;
- END
- ELSE
- BEGIN;
- INC(insert_buffer);
- IF insert_buffer > line_buffer_max THEN
- insert_buffer := 1;
- END;
- line_buffer[insert_buffer] := operator_line_in^;
-
- current_buffer := insert_buffer;
-
- END;
-
- operator_line_in^ := operator_line_in^ + cr;
-
- opr_line_done := TRUE;
-
- i := window_cursor_update(1);
- window_erase_eol(window_reset);
-
- EXIT;
- END;
-
- (*---------------------------------------------------------------------*)
- (* Backspace *)
- (*---------------------------------------------------------------------*)
-
- bs: BEGIN;
-
- i := window_cursor_update(0);
-
- IF i > 1 THEN
- BEGIN;
-
- IF i = 2 THEN
- operator_line_in^ := substr(operator_line_in^, 2, 0)
- ELSE
- IF i > LENGTH(operator_line_in^) THEN
- operator_line_in^ := substr(operator_line_in^, 1, i-2)
- ELSE
- operator_line_in^ := substr(operator_line_in^, 1, i-2) +
- substr(operator_line_in^, i, 0);
-
- color(opt_block.status_color);
-
- i := window_cursor_update(i-1);
-
- CLREOL;
-
- IF i <= LENGTH(operator_line_in^) THEN
- WRITE(substr(operator_line_in^, i-1, 0));
-
- i := window_cursor_update(i-1);
-
- END;
-
- END;
-
- (*---------------------------------------------------------------------*)
- (* Anything else -- Just print it. *)
- (*---------------------------------------------------------------------*)
-
- ELSE
- BEGIN;
-
- IF LENGTH(operator_line_in^) < line_max THEN
- BEGIN;
- COLOR(opt_block.status_color);
- i := window_cursor_update(0);
- IF i > LENGTH(operator_line_in^) THEN
- BEGIN;
- WRITE(this_key);
- operator_line_in^ := operator_line_in^ + this_key;
- END
- ELSE
- BEGIN;
- IF operator_insert THEN
- BEGIN;
- IF i > 1 THEN
- operator_line_in^ := substr(operator_line_in^, 1, i-1)
- + this_key
- + substr(operator_line_in^, i, 0)
- ELSE
- operator_line_in^ := this_key + operator_line_in^;
- END
- ELSE
- operator_line_in^[i] := this_key;
- WRITE(substr(operator_line_in^, i, 0));
- i := window_cursor_update(i+1);
- END;
- END
- ELSE
- BEGIN;
- SOUND(440);
- DELAY(100);
- NOSOUND;
- END;
- END;
-
- END;
-
- END;
-
- (*===========================================================================*)
- (* Handle a function key or an extended key *)
- (*===========================================================================*)
-
- PROCEDURE function_key;
-
- VAR
- b : BOOLEAN;
- i : INTEGER;
- j : INTEGER;
-
- {$IFDEF NODEBUG}
- bug_port : port_block_ptr;
- bug_tcb : tcb_ptr;
- bug_chn : str_m_chain;
- {$ENDIF}
-
- BEGIN;
-
- CASE this_key OF
-
- (*---------------------------------------------------------------------*)
- (* Right/Left Arrows : Move cursor *)
- (*---------------------------------------------------------------------*)
-
- ekey_left_arrow,
- ekey_right_arrow:
- BEGIN;
-
- i := window_cursor_update(0);
- IF this_key = ekey_right_arrow THEN
- INC(i)
- ELSE
- DEC(i);
- IF (i > 0) AND (i <= (LENGTH(operator_line_in^) + 1)) THEN
- i := window_cursor_update(i);
-
- END;
-
- (*---------------------------------------------------------------------*)
- (* Delete : Delete character above the cursor; *)
- (*---------------------------------------------------------------------*)
-
- ekey_delete:
- BEGIN;
-
- i := window_cursor_update(0);
- IF (i <= LENGTH(operator_line_in^)) THEN
- BEGIN;
- IF i > 1 THEN
- operator_line_in^ := substr(operator_line_in^, 1, i-1)
- + substr(operator_line_in^, i+1, 0)
- ELSE
- operator_line_in^ := substr(operator_line_in^, 2, 0);
- color(opt_block.status_color);
- CLREOL;
- WRITE(substr(operator_line_in^, i, 0));
- i := window_cursor_update(i);
- END;
-
- END;
-
- (*---------------------------------------------------------------------*)
- (* Insert : Flip cursor *)
- (*---------------------------------------------------------------------*)
-
- ekey_insert:
- BEGIN;
-
- i := window_cursor_update(0);
- color(opt_block.status_color);
- operator_insert := NOT operator_insert;
- window_cursor_size(operator_insert);
-
- END;
-
- (*---------------------------------------------------------------------*)
- (* F1: Move cursor to front of line *)
- (*---------------------------------------------------------------------*)
-
- ekey_f1:
- i := window_cursor_update(1);
-
- (*---------------------------------------------------------------------*)
- (* F2: Erase to end of line *)
- (*---------------------------------------------------------------------*)
-
- ekey_f2 : BEGIN;
-
- i := window_cursor_update(0);
- color(opt_block.status_color);
-
- IF i > 1 THEN
- operator_line_in^ := substr(operator_line_in^, 1, i-1)
- ELSE
- operator_line_in^ := '';
-
- j := i;
- WHILE j <= line_max DO
- BEGIN;
- INC(j);
- WRITE(' ');
- END;
-
- i := window_cursor_update(i);
-
- END;
-
- (*---------------------------------------------------------------------*)
- (* F3: Close operator window and any sub task *)
- (*---------------------------------------------------------------------*)
-
- ekey_f3 : close_operator_session;
-
- (*---------------------------------------------------------------------*)
- (* F4: Clear window *)
- (*---------------------------------------------------------------------*)
-
- ekey_f4 : BEGIN;
-
- IF opr_window_open THEN
- i := window_operator
- ELSE
- i := who_is_in_window(window_bottom_screen);
-
- window_select(i);
- window_clear(i);
-
- END;
-
- (*---------------------------------------------------------------------*)
- (* F5: Swap windows *)
- (*---------------------------------------------------------------------*)
-
- ekey_f5 : window_swap;
-
- (*---------------------------------------------------------------------*)
- (* F7: Kill operator sub task *)
- (*---------------------------------------------------------------------*)
-
- ekey_f7 : BEGIN;
- operator_line_c := TRUE;
- op_busy := FALSE;
- END;
-
- (*---------------------------------------------------------------------*)
- (* F9, F10 : Retrieve *)
- (*---------------------------------------------------------------------*)
-
- ekey_f9,
- ekey_f10 : BEGIN;
-
- IF high_buffer < 1 THEN
- EXIT;
-
- IF this_key = ekey_f9 THEN
- BEGIN;
- INC(current_buffer);
- IF current_buffer > high_buffer THEN
- current_buffer := 1;
- END;
-
- operator_line_in^ := line_buffer[current_buffer];
- j := ORD(line_buffer[current_buffer, 0]);
-
- color(opt_block.status_color);
-
- i := window_cursor_update(1);
- WRITE(operator_line_in^);
-
- CLREOL;
-
- i := window_cursor_update(j+1);
-
- IF this_key = ekey_f10 THEN
- BEGIN;
- DEC(current_buffer);
- IF current_buffer < 1 THEN
- current_buffer := high_buffer;
- END;
-
- END;
-
- (*---------------------------------------------------------------------*)
- (* UP/DOWN ARROW, HOME, END; Scroll bottom window *)
- (*---------------------------------------------------------------------*)
-
- ekey_up_arrow, ekey_down_arrow, ekey_home, ekey_end:
- BEGIN;
-
- IF opr_window_open THEN
- window_select(window_operator)
- ELSE
- BEGIN;
- i := who_is_in_window(window_bottom_screen);
- window_select(i);
- END;
-
- CASE this_key OF
- ekey_up_arrow, ekey_down_arrow:
- scr_window(this_key = ekey_up_arrow, 1);
- ekey_home, ekey_end:
- scr_window(this_key = ekey_home, 9999);
- END;
-
- END;
-
- (*---------------------------------------------------------------------*)
- (* PG-UP, PG-DOWN, CTL-PG-UP, CTL-PG-DOWN: Scroll top window *)
- (*---------------------------------------------------------------------*)
-
- ekey_page_down, ekey_page_up,
- ekey_control_page_down, ekey_control_page_up:
- BEGIN;
-
- i := who_is_in_window(window_top_screen);
- window_select(i);
-
- CASE this_key OF
- ekey_page_down, ekey_page_up:
- scr_window(this_key = ekey_page_up, 1);
- ekey_control_page_down, ekey_control_page_up:
- scr_window(this_key = ekey_control_page_up, 9999);
- END;
-
- END;
-
- (*---------------------------------------------------------------------*)
- (* ALT-X: Exit immediately *)
- (*---------------------------------------------------------------------*)
-
- ekey_x : shutdown_bbs;
-
- (*---------------------------------------------------------------------*)
- (* ALT-A: Abort printer *)
- (*---------------------------------------------------------------------*)
-
- ekey_a : kill_printer := TRUE;
-
- (*---------------------------------------------------------------------*)
- (* Semaphore debugger -- ALT-O *)
- (*---------------------------------------------------------------------*)
-
- {$IFDEF SEMABUG}
-
- #$18: BEGIN;
- dump_reason('ALT-O Semaphore bug');
- dump_semaphores;
- END;
-
- {$ENDIF}
-
- (*---------------------------------------------------------------------*)
- (* Free list debugger -- ALT-I *)
- (*---------------------------------------------------------------------*)
-
- {$IFDEF DUMP_FREE}
-
- #$17: BEGIN;
- dump_reason('ALT-N processing dump free');
- dump_all_thread;
- END;
-
- {$ENDIF}
-
- (*---------------------------------------------------------------------*)
- (* Free list debugger -- ALT-O *)
- (*---------------------------------------------------------------------*)
-
- {$IFDEF DUMP_FREE}
-
- #$18: BEGIN;
- dump_reason('ALT-O processing dump free');
- dump_all;
- END;
-
- {$ENDIF}
-
- (*---------------------------------------------------------------------*)
- (* Action list debugger -- ALT-O *)
- (*---------------------------------------------------------------------*)
-
- {$IFDEF DUMP_SEARCH}
-
- #$18: BEGIN;
- dump_reason('ALT-O processing dump action');
- dump_action_all;
- END;
-
- {$ENDIF}
-
- (*---------------------------------------------------------------------*)
- (* Node debugger -- ALT-U *)
- (*---------------------------------------------------------------------*)
-
- {$IFDEF NODEBUG}
-
- #$16: BEGIN;
- dump_reason('ALT-P Node debugging');
-
- bug_port := ring_port;
-
- REPEAT
-
- IF bug_port^.port_type = port_g8bpq THEN
- BEGIN;
-
- FOR i := 1 TO bug_port^.max_chan DO
- BEGIN;
-
- bug_tcb := bug_port^.connected^[i];
-
- IF bug_tcb <> NIL THEN
- BEGIN;
-
- bug_chn := bug_tcb^.tnc_in_chn;
- WHILE bug_chn <> NIL DO
- BEGIN;
- WRITELN('Port ', bug_port^.port_char,
- ' -- tcb ', bug_tcb^.port_chan_s,
- ' -- chan ', bug_chn^.str_m_chan,
- ' -- type ', bug_chn^.str_m_type,
- ' -- ',
- COPY(bug_chn^.str_m_data.str_data, 1, 15));
- bug_chn := bug_chn^.str_m_next;
- END;
-
- END;
-
- END;
-
- END;
-
- bug_port := bug_port^.next_port;
-
- UNTIL bug_port = ring_port
-
- END;
-
- {$ENDIF}
-
- (*---------------------------------------------------------------------*)
- (* Window debugger -- ALT-Y *)
- (*---------------------------------------------------------------------*)
-
- {$IFDEF WINBUG}
-
- #$15: dump_window_all;
-
- {$ENDIF}
-
- (*---------------------------------------------------------------------*)
- (* Port debugger -- ALT-Y *)
- (*---------------------------------------------------------------------*)
-
- {$IFDEF PORTBUG}
-
- #$15: dump_all_thread;
-
- {$ENDIF}
-
- (*---------------------------------------------------------------------*)
- (* Unknown -- Beep! *)
- (*---------------------------------------------------------------------*)
-
- ELSE
- BEGIN;
- status_window_change := TRUE;
- SOUND(440);
- DELAY(100);
- NOSOUND;
- END;
-
- END;
-
- END;
-
- (*===========================================================================*)
- (* Make operator session go by by *)
- (*===========================================================================*)
-
- PROCEDURE close_operator_session;
-
- BEGIN;
-
- active_tcb^.uid_data.user_last := current_day_time;
- IF active_tcb^.last_l_time > active_tcb^.uid_data.user_l_time THEN
- active_tcb^.uid_data.user_l_time := active_tcb^.last_l_time;
-
- update_uid(@active_tcb^.uid_data);
-
- operator_line_c := TRUE;
- op_busy := FALSE;
-
- window_deactivate(window_operator);
- opr_window_open := FALSE;
-
- free_task_mem_all(active_tcb);
-
- END;
-
- (*===========================================================================*)
- (* Initialization *)
- (*===========================================================================*)
-
- PROCEDURE operator_init_session;
-
- BEGIN;
-
- operator_insert := FALSE;
- current_buffer := 0;
- high_buffer := 0;
- insert_buffer := 0;
-
- END;
-
- END.